package com.itmd.controller;

import com.itmd.domain.Account;
import com.itmd.service.AccountService;
import com.itmd.service.impl.AccountServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("/account")
public class AccountController {

    @Autowired
    AccountService accountService;


    @RequestMapping(value = "/save",method = RequestMethod.POST,produces = "text/html;charset=utf-8")
    @ResponseBody
    public String save(Account account) throws IOException {
        System.out.println(account);
        accountService.save(account);
        return "保存成功";
    }


    @RequestMapping(value = "/findAll")
    public ModelAndView findAll() throws IOException {
        List<Account> all = accountService.findAll();
        ModelAndView modelAndView = new ModelAndView();
        System.out.println(all);
        modelAndView.addObject("accountlist",all);
        modelAndView.setViewName("accountlistPage");
        return modelAndView;
    }


}
